<?php
/**
 * Created by PhpStorm.
 * User: Yuri
 * DateTime: 2017-4-23 13:49
 */

namespace common\collection;
use Yii;
use common\helpers\PublicFun;
use backend\config\routeParams;

class BackendCommon{

    public static function init(){
        $cookies = Yii::$app->request->cookies;
        if (($cookie = $cookies->get('MytipIdBack')) !== null) {
            return $cookie->value;
        }else{
            return false;
        }
    }
    public static function rbac(){
        if(Yii::$app->request->isGet){
            $cookies = Yii::$app->request->cookies->get('MytipIdBack');
            $JsonData['MytipId'] = $cookies->value;
            //左侧导航栏
            $url = routeParams::HttpUrl('ControllerActionGetList');
            $result = PublicFun::PostPackage($JsonData, $url);
            $result = json_decode($result['Body'],true);
            $ControllerId = Yii::$app->controller->id;
            $ActionId = Yii::$app->controller->action->id;
            $isTrue = false;
//            var_dump($JsonData);
//            var_dump($result);
//            exit;
            foreach($result['Models'] as $key => $val){
                if( $ControllerId.'/'.$ActionId == 'userinfo/index'){
                    $isTrue = true;
                    break;
                }
                if($val['ControllerCode'] == $ControllerId){
                    if(
                        // ($ControllerId.'/'.$ActionId == 'sceneactive/create') ||
                        // ($ControllerId.'/'.$ActionId == 'promote/sales')||
                        // ($ControllerId.'/'.$ActionId == 'promote/reservation')||
                        // ($ControllerId.'/'.$ActionId == 'promote/reservation1')||
                        // ($ControllerId.'/'.$ActionId == 'promote/reservation2')||
                        // ($ControllerId.'/'.$ActionId == 'promote/activity') ||
                        // ($ControllerId.'/'.$ActionId == 'sceneactive/detial') ||
                        // ($ControllerId.'/'.$ActionId == 'subordinate/detail' ) ||
                        // ($ControllerId.'/'.$ActionId == 'customer/demo') ||
                        // ($ControllerId.'/'.$ActionId == 'task/createtask') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/bargain') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/newregistercreate') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/newregistertracking') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/openboxcreate') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/openboxtracking') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/openboxgiftlist') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/turnplatecreate') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/turnplate') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/turnplatetracking') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/turnplategiftlist') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/turnplaterecord') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/groupcreate') ||
                        // ($ControllerId.'/'.$ActionId == 'enterpriseplatform/add') ||
                        // ($ControllerId.'/'.$ActionId == 'enterpriseplatform/employee') ||
                        // ($ControllerId.'/'.$ActionId == 'website/addcase') ||
                        // ($ControllerId.'/'.$ActionId == 'drainage/tracking')
                        ($ControllerId.'/'.$ActionId == 'sceneactive/create') ||
                        ($ControllerId.'/'.$ActionId == 'promote/sales')||
                        ($ControllerId.'/'.$ActionId == 'promote/reservation')||
                        ($ControllerId.'/'.$ActionId == 'promote/reservation1')||
                        ($ControllerId.'/'.$ActionId == 'promote/reservation2')||
                        ($ControllerId.'/'.$ActionId == 'promote/activity') ||
                        ($ControllerId.'/'.$ActionId == 'sceneactive/detial') ||
                        ($ControllerId.'/'.$ActionId == 'subordinate/detail' ) ||
                        ($ControllerId.'/'.$ActionId == 'customer/demo') ||
                        ($ControllerId.'/'.$ActionId == 'task/createtask') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/bargain') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/newregistercreate') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/newregistertracking') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/openboxcreate') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/openboxtracking') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/openboxgiftlist') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/turnplatecreate') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/turnplate') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/turnplatetracking') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/turnplategiftlist') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/turnplaterecord') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/grouptracking') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/groupcreate') ||
                        ($ControllerId.'/'.$ActionId == 'customer/course') ||
                        ($ControllerId.'/'.$ActionId == 'website/addcase') ||
                        ($ControllerId.'/'.$ActionId == 'enterpriseplatform/add') ||
                        ($ControllerId.'/'.$ActionId == 'enterpriseplatform/employee') ||
                        ($ControllerId.'/'.$ActionId == 'drainage/tracking')
                    ){
                        $isTrue = true;
                        break;
                    }
                    foreach($val['ActionList'] as $k => $v){
                        if($v['ActionCode'] == $ActionId){
                            $isTrue = true;
                            break;
                        }
                    }
                }
            }
            return $isTrue;
        }else{
            return true;
        }



    }
}
